package per.zhang.vaccinesys.serverConsumer.dto.respone;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.format.annotation.DateTimeFormat;
import per.zhang.vaccinesys.serverConsumer.entity.VaccineOrder;

import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @auther zhang
 * @ TO DO
 * @creatTime 2021/1/26 16:51
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VaccineOrderRespondDTO {
    /**
     * 疫苗采购订单id
     */

    @ApiModelProperty(value = "疫苗采购订单id",name = "orderId",dataType = "String")
    private String orderId;

    /**
     * 疫苗名字
     */
    private String vaccineName;

    /**
     * 疫苗订单的疫苗数量
     */
    private Integer vaccineNum;

    /**
     * 疫苗单价
     */
    private BigDecimal vaccinePrice;

    /**
     * 总价
     */
    private BigDecimal totalPrice;

    /**
     * 创建时间
     */
    //@DateTimeFormat(pattern = "YYYY-MM-DD hh:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date creatTime;

    private String state;


    public VaccineOrderRespondDTO (VaccineOrder vaccineOrder, String vaccineName) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        PropertyUtils.copyProperties(this, vaccineOrder);
        this.vaccineName = vaccineName;
        this.totalPrice = this.vaccinePrice.multiply(new BigDecimal(this.vaccineNum));
    }

}
